package com.ruoyi.core.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.core.domain.WesItem;
import com.ruoyi.core.service.IWesItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/core/item")
public class WesItemController extends BaseController
{
    @Autowired
    private IWesItemService wesItemService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('core:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(WesItem wesItem)
    {
        startPage();
        List<WesItem> list = wesItemService.selectWesItemList(wesItem);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('core:item:export')")
    @Log(title = "货品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WesItem wesItem)
    {
        List<WesItem> list = wesItemService.selectWesItemList(wesItem);
        ExcelUtil<WesItem> util = new ExcelUtil<WesItem>(WesItem.class);
        util.exportExcel(response, list, "货品管理数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('core:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(wesItemService.selectWesItemByItemId(itemId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('core:item:add')")
    @Log(title = "货品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WesItem wesItem)
    {
        wesItem.setCreatorBy(getUsername());
        wesItem.setCreatedTime(DateUtils.getNowDate());
        return toAjax(wesItemService.insertWesItem(wesItem));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('core:item:edit')")
    @Log(title = "货品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WesItem wesItem)
    {
        return toAjax(wesItemService.updateWesItem(wesItem));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('core:item:edit')")
    @Log(title = "货品管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody WesItem item)
    {
        item.setUpdateBy(getUsername());
        item.setUpdateTime(DateUtils.getNowDate());
        return toAjax(wesItemService.updateItemStatus(item));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('core:item:remove')")
    @Log(title = "货品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(wesItemService.deleteWesItemByItemIds(itemIds));
    }
}
